using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.Core.DataInterfaces;
using CMS.Presenters;
using CMS.Core.Domain;
using CMS.Data;
using CMS.Data.Common;
using AjaxPro;

namespace CMS.Web
{
    public partial class ChangePassword : System.Web.UI.UserControl, IChangePasswordView
    {
        ChangePasswordPresenter presenter;
        INguoiSuDungDao iNsdDao;
        public NguoiSuDungInfo userInfo = null;
        //LDAP lDap = new LDAP();

        public ChangePassword() { 
            iNsdDao = NHibernateDaoFactory.Instance.GetNguoiSuDungDao();
            this.presenter = new ChangePasswordPresenter(this, iNsdDao);
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            RaiseClientEvent();
            userInfo = (NguoiSuDungInfo)Session["UserInfo"];
        }

       

        private void RaiseClientEvent() {
            btnUpdate.Click += new EventHandler(btnUpdate_Click);
            Utility.RegisterTypeForAjax(typeof(CMS.Presenters.ChangePasswordPresenter));
            txtPassOld.Attributes.Add("onBlur", "return CheckBeforeUpdate();");
            txtPassOld.Attributes.Add("onFocus", "DelMessage();");
            txtPassNew.Attributes.Add("onFocus", "DelMessage();");
            txtPassConfirm.Attributes.Add("onFocus", "DelMessage();");
            btnUpdate.Attributes.Add("onclick", "return CheckBeforeUpdate();");
        }

        void btnUpdate_Click(object sender, EventArgs e)
        {
            //if(lDap.IsUsingLDAP){
            //    lDap.SetPassword(userInfo.TaiKhoan, this.passOld, this.passNew);
            //}
            this.presenter.UpdatePassWord(userInfo.ID, this.passNew);
            lblMessage.Style.Add(HtmlTextWriterStyle.Display, "Block");
        }





        #region IChangePasswordView Members

        public string passOld
        {
            get { return this.txtPassOld.Text; }
        }

        public string passNew
        {
            get { return this.txtPassNew.Text; }
        }

        public string passConfirm
        {
            get { return this.txtPassConfirm.Text; }
        }

        #endregion
    }
}